package com.nsoft.thickclient.trackMove.gc;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import com.nsoft.thickclient.controller.ScreenController;
import com.nsoft.thickclient.model.ModelEvent;
import com.nsoft.thickclient.model.ModelListener;
import com.nsoft.thickclient.trackMove.util.TrackMoveButtonPanel;

public class GcViewController extends ScreenController implements ModelListener {
	private JPanel mainPanel;

	private GcView gcView;

	private TrackMoveButtonPanel buttonPanel;

	@Override
	public void close() {
		mainPanel = null;
		gcView.getModel().removeAllModelListeners();
		gcView.getModel().removeAllMandatoryProperties();
		gcView = null;
		buttonPanel = null;

	}

	@Override
	public String getScreenTitle() {
		return "Manage GC";
	}

	@Override
	public JPanel getView() {
		return mainPanel;
	}

	@Override
	public void init() {
		gcView = new GcView(null);
		mainPanel = new JPanel(new BorderLayout());
		mainPanel.add(gcView, BorderLayout.PAGE_START);
		buttonPanel = new TrackMoveButtonPanel(this, false);
		mainPanel.add(buttonPanel, BorderLayout.PAGE_END);
		gcView.getModel().addModelListener(this);

	}

	public void propertyChanged(ModelEvent event, Object oldValue) {
		buttonPanel.enableSave(event.getModel().isValied());

	}

	public void valueObjectChanged(ModelEvent event) {
		// TODO Auto-generated method stub

	}

	public void doNew() {
		gcView.getWorkingBean();
	}

	public void doSave() {
		gcView.getWorkingBean();
	}

	public void doCancel() {
		getApplicationController().closeScreen(this);
	}

}
